﻿<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:v="clr-namespace:ShredTheLog.Views;assembly=ShredTheLog.Views"
    xmlns:vm="clr-namespace:ShredTheLog.ViewModels;assembly=ShredTheLog.ViewModels"
    xmlns:cnv="clr-namespace:ShredTheLog.Converters;assembly=ShredTheLog.Converters"
    xmlns:c="clr-namespace:ShredTheLog.Controls;assembly=ShredTheLog.Controls"
    xmlns:tk="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
    >

    <DataTemplate DataType="{x:Type vm:UserSearchViewModel}">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>

            <TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" HorizontalAlignment="Stretch"  Margin="0, 2, 0, 2" TextWrapping="Wrap" TextAlignment="Center">
                <TextBlock.Text>
                    <MultiBinding StringFormat="{c:LocalizedString s_MembersFound}">
                        <Binding Path="TotalUserCount"/>
                        <Binding Path="PageIndex" Converter="{x:Static cnv:IncrementingConverter.Default}"/>
                        <Binding Path="PageCount"/>
                    </MultiBinding>
                </TextBlock.Text>
            </TextBlock>
            <tk:DataGrid x:Name="grid" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" ItemsSource="{Binding Users}" CanUserSortColumns="False">
                <ItemsControl.ItemContainerStyle>
                    <Style TargetType="{x:Type tk:DataGridRow}">
                        <Setter Property="ContextMenu">
                            <Setter.Value>
                                <ContextMenu c:Extensions.Items="{Binding Converter={x:Static vm:UserMenuItemsConverter.Default}}" DataContext="{Binding RelativeSource={RelativeSource Mode=Self}, Path=PlacementTarget.DataContext}"/>
                            </Setter.Value>
                        </Setter>
                        <Setter Property="ToolTip" Value="{StaticResource UserToolTip}"/>
                    </Style>
                </ItemsControl.ItemContainerStyle>
                <tk:DataGrid.Columns>
                    <tk:DataGridTemplateColumn Header="{x:Null}" CanUserResize="False">
                        <tk:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <ContentPresenter Content="{Binding Path=Gender, Mode=OneWay}" HorizontalAlignment="Center"/>
                            </DataTemplate>
                        </tk:DataGridTemplateColumn.CellTemplate>
                    </tk:DataGridTemplateColumn>
                    <tk:DataGridTextColumn Header="{c:LocalizedString s_Name}" Binding="{Binding Path=Name, Mode=OneWay}" Width="*"/>
                    <tk:DataGridTextColumn Header="{c:LocalizedString s_Country}" Binding="{Binding Path=Country, Mode=OneWay, Converter={x:Static cnv:CountryConverter.Default}}" Width="*"/>
                    <tk:DataGridTextColumn Header="{c:LocalizedString s_Age}" Binding="{Binding Path=Age, Mode=OneWay}">
                        <tk:DataGridTextColumn.ElementStyle>
                            <Style TargetType="{x:Type TextBlock}">
                                <Setter Property="TextAlignment" Value="Right"/>
                            </Style>
                        </tk:DataGridTextColumn.ElementStyle>
                    </tk:DataGridTextColumn>
                </tk:DataGrid.Columns>
            </tk:DataGrid>

            <Button Grid.Row="2" Grid.Column="0" Content="{c:LocalizedString s_Simple_PreviousPage}" ToolTip="{c:LocalizedString s_PreviousPage}" Command="{Binding PreviousPageCommand}"/>
            <Button Grid.Row="2" Grid.Column="1" Content="{c:LocalizedString s_NewSearch}" Command="{Binding ShowConditionsCommand}" HorizontalAlignment="Center" MinWidth="{x:Static c:UX.ButtonWidth}"/>
            <Button Grid.Row="2" Grid.Column="2" Content="{c:LocalizedString s_Simple_NextPage}" ToolTip="{c:LocalizedString s_NextPage}" Command="{Binding NextPageCommand}"/>
        </Grid>

        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding IsLoading}" Value="true">
                <Setter TargetName="grid" Property="Cursor" Value="Wait"/>
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>
</ResourceDictionary>